<?php
/*
 * 留言板
 */
namespace app\admin\controller;
use app\common\controller\AdminBase;
use think\facade\Db;
use think\facade\Session;
use app\common\model\Message as MessageModel;

class Message extends AdminBase
{

    public function lists()
    {
        $param = $this->request->param();
        if (!empty($param['title'])) {
            $where = function ($query) use ($param){$query->where('title','LIKE', '%'.trim($param['title']).'%');};
        }else{
            $where = 1;
        }
        $list = MessageModel::getMessageList($where);
        return $this->fetch('index',['list'=>$list]);
    }
    //回复
    public function reply()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $param['reply_id'] = abs(md6(AdminId(),true));
            $param['is_reply'] = 1;
            $result = MessageModel::update($param);
            !$result && $this->error($this->errorMsg);
            insert_admin_log('回复了留言');
            $this->success('回复成功');
        }
        return $this->fetch('save',['data' => Db::table('message')->find(input('id'))]);
    }
    //修改状态
    public function status()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $result = MessageModel::update($param);
            !$result && $this->error($this->errorMsg);
            insert_admin_log('修改了留言状态');
            $this->success('修改成功');
        }
    }
    //删除
    public function del()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            MessageModel::destroy($param['id']);
            insert_admin_log('删除了留言');
            $this->success('删除成功');
        }
    }




}
